package org.sharelife.dao.impl;

import org.sharelife.dao.IPictureDAO;
import org.sharelife.entity.Picture;
import org.sharelife.util.PageBean;

public class PictureDAOImpl extends SuperHibernateDAOImpl implements IPictureDAO {

	@Override
	public Integer add(Picture picture) {
		return super.save(picture);
	}

	@Override
	public PageBean findForPage(int userId, int pageSize, int page) {
		String hql = "from Picture where user.id = " + userId + " order by id desc";
		return super.queryForPage(hql, pageSize, page);
	}

	@Override
	public PageBean findAll(int pageSize, int page) {
		String hql = "from Picture order by id desc";
		return super.queryForPage(hql, pageSize, page);
	}

	@Override
	public Picture findById(int id) {
		return (Picture) super.get(Picture.class, id);
	}

	@Override
	public void delete(int id) {
		super.delete(Picture.class, id);
	}

	@Override
	public Integer deleteAll() {
		return super.deleteAll(Picture.class);
	}

	@Override
	public PageBean queryForPage(int pageSize, int page) {
		String hql = "from Picture order by id";
		return super.queryForPage(hql, pageSize, page);
	}

	@Override
	public PageBean queryByKeyWord(String keyWord, int pageSize, int page) {
		String hql = "from Picture where user.userName like '%" + keyWord + "%' or picType like '%" + keyWord + "%'";
		return super.queryForPage(hql, pageSize, page);
	}

	@Override
	public PageBean queryByType(String keyWord, int pageSize, int page) {
		String hql = "from Picture where picType = '" + keyWord + "'";
		return super.queryForPage(hql, pageSize, page);
	}
}